package com.itheima.trade.config;

import com.itheima.model.common.feign.fallback.UserClient;
import com.itheima.trade.intercepter.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//声明配置类
//spring自动装配 包含DispatcherServlet的类（Http请求的Spring Mvc 前端控制器）才会加载这个类
//网关引用了commeon 包，但是没有DispatcherServlet，所以不会加载这个类  解决 网关冲突和mvc冲突
//@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {
    //构建拦截器

    @Autowired
    private UserClient userClient;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new TokenInterceptor(userClient)).addPathPatterns("/**");
    }
}
